set scheme s1color

*Parameters--------------------------------------------------------------------
local exch=2288 //Exchange rate TSH per USD

*Leader predictions, rmse and R2----------------------------------------------------
use "${sdir}/Leaders_and_Owners_cln.dta", clear

*Rename and relabel------------------------------------------------------------
rename (s9_q_1_own q42_ldr)(wtp wtp_ldr)
replace wtp=wtp/`exch'
replace wtp_ldr=wtp_ldr/`exch'

*generate leader-wtp differences
gen wtp_dff=(wtp_ldr-wtp)
bysort trt_grp: egen wtp_dff_mn=mean(wtp_dff)
gen wtp_dff_dmnd= wtp_dff-wtp_dff_mn
gen wtp_dff_dmnd_abs=abs(wtp_dff_dmnd)
gen wtp_dff_abs=abs(wtp_dff)
label var wtp_dff_abs "\makecell{abs[\widehat{w}_{ol}-w_{o}]}" 

*Owner Characteristics----------------------------------------------------------
*poor
gen poor=(s1_q_6_1_own==0 )
label var poor "\makecell{Very\\poor}" //NB: Very poor is below 50k or $23
*low education 
gen low_edu=(s1_q_5_1_own<=2)
label var low_edu "\makecell{Low \\ Education}" 
*old
gen old =(s1_q_2_1_own>3)
label var old "Age$>$60"
*sole owner female
gen sole_female=(s0_q_1_own==1 & s1_q_1_1_own==1)
label var sole_female "\makecell{Sole\\Female\\Owner}"
*with dependants
replace s1_q_4_1_own=0 if missing(s1_q_4_1_own)==1
gen dependents=(s1_q_4_1_own>=1)
label var dependents "\makecell{Has\\Children}"

*Leader beliefs about owner-----------------------------------------------------
*who is poorest
gen poor_ldr_perception=(q27_ldr>10)
label var poor_ldr_perception "\makecell{Believed\\poorest}"
*who will benefit the most
gen high_ben=(q29_ldr<=5)
label var high_ben "\makecell{Believed will\\benefit most}"
*who has highest invoice value
gen high_inv=(q28_ldr<=5)
label var high_inv "\makecell{Believed highest\\invoice}"
*with dependent children
gen owner_bequeth_perception=q32_ldr //closest we have is "mjumbe predicts owner is interested in bequething plot to their children"
label var owner_bequeth_perception "\makecell{Believed\\interested in\\bequeathment}"
*with pending loans
gen owner_loan_percetion=q35_ldr //closest we have is "Mjumbe predicts owner is interested in taking a loan with their land"
label var owner_loan_percetion "\makecell{Believed\\interested\\in loans}"

*Relationship between Leader and Owner------------------------------------------
*Familiar with owner
gen familiar=(q10_ldr>=3)
tab q10_ldr familiar
label var familiar "Familiar"
*requested services by owner
gen requested_services=(q11_ldr>=3)
label var requested_services "Used services"
*family member OR close friend
gen family_or_friend=(q12_ldr==1 | q13_ldr==1)
label var family_or_friend "\makecell{Family or\\friend}"
*meets at religious gatherings
gen meets_religous=q14_ldr
label var meets_religous "\makecell{Meet at\\religious\\gatherings}"
*recognizes as highly esteemed by the community
gen high_esteem=q15_ldr
label var high_esteem "\makecell{Recognised\\as highly\\esteemed}"


*Leader Characteristics----------------------------------------------------------
*poor
gen poor_leader=(q9_1_ldr<=1)
label var poor_leader "\makecell{Poor}" //NB: Poor is below 100k or $46
*low education 
gen low_edu_leader=(q8_1_ldr<=2)
label var low_edu_leader "\makecell{Low\\Education}" 
*old
gen old_leader =(age_ldr==4)
label var old_leader "Age$>$60"
*have paid own title deed invoice
gen paid_own=(q4_2_ldr==1)
label var paid_own "\makecell{Paid own\\title deed}"
*CRO quiz score=9 or 10
gen top_quiz=(quiz_score_ldr==9 | quiz_score_ldr==10)
label var top_quiz "\makecell{Top Quiz\\Score}"
*Opposition Party
gen opposition=(q1_1_ldr==1)
label var opposition "\makecell{Opposition\\Party}"


*run regressions================================================================
*Panel (A) - Owner characteristics
local dep_lst poor low_edu old sole_female dependents
local mtitles1 ""
local c=0
foreach v in `dep_lst' {
    preserve
    local c=`c'+1
    gen x=`v'
	eststo pnl1_`c': reghdfe wtp_dff x if trt_grp_ldr==2, vce(cluster shina_leader_id) absorb(shina_id)
	local wR2di: di %5.4f e(r2_a_within)
	estadd local wR2="`wR2di'"
	local lab: var label `v'
	local mtitles1 `"`mtitles1' "`lab'""'
	restore
	}

*Panel (B) - Leader beliefs about owner and relationships
local dep_lst poor_ldr_perception owner_loan_percetion owner_bequeth_perception family_or_friend meets_religous
local mtitles2 ""
local c=0
foreach v in `dep_lst' {
    preserve
    local c=`c'+1
    gen x=`v'
	eststo pnl2_`c': reghdfe wtp_dff x if trt_grp_ldr==2, vce(cluster shina_leader_id) absorb(shina_id#leader_id)
	local wR2di: di %5.4f e(r2_a_within)
	estadd local wR2="`wR2di'"
	local lab: var label `v'
	local mtitles2 `"`mtitles2' "`lab'""'
	restore
	}

*Panel (C) - Leader Characteristics
local dep_lst poor_leader low_edu_leader old_leader paid_own opposition /*top_quiz*/
local mtitles3 ""
local c=0
foreach v in `dep_lst' {
    preserve
    local c=`c'+1
    gen x=`v'
	eststo pnl3_`c': reghdfe wtp_dff x if trt_grp_ldr==2, vce(cluster shina_leader_id) absorb(shina_id)
	local wR2di: di %5.4f e(r2_a_within)
	estadd local wR2="`wR2di'"
	local lab: var label `v'
	local mtitles3 `"`mtitles3' "`lab'""'
	restore
	}

	
*write to file==================================================================
gen x=.
label var x "Group Difference"

local note ///
	This table presents results on heterogeneity of the overprediction in the stakes group. Each observation is a leader-plot pair. The dependent variable is always leader prediction error ($\hat{w}_{ol}-w_{o}$). Neighbourhood fixed effects are included in all models, and panel B also includes leader fixed effects. Panel A uses owner indicators: in col. 1 household income is below 22 USD, col. 2 no more than primary education, col. 3 is over 60, col 4. is owned solely by a woman, and col. 5 at least one child. Panel B uses leader-owner indicators: col. 1 the leader believes that the owner is in the bottom third in terms of income, col. 2 the leader believes that the owner is interested in using their land as collateral, col. 3 the leader believes that the owner wishes to bequeath their plot, col. 4 family members or friends, and col. 5 meet together for religious gatherings. Panel C uses leader indicators: col. 1 household income is below 44 USD, col. 2 has no more than primary education, col. 3 is over 60 years old, col. 4 has paid for the title deed to their plot, and col. 5 belongs to the opposition party. Standard errors in parentheses are clustered at leader level. \sym{*}\(p<0.10\),	\sym{**}\(p<0.05\), \sym{***}\(p<0.01\).
*put all panels together in one table
//top panel 
esttab pnl1* using "tables/predictions_wtp_heterog.tex", ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mtitles(`mtitles1') ///
	stats(N r2, label("Observations" "R$^2$")) ///
	se label wrap fragment ///
	nobaselevels nocons ///
	prehead("\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} {\centering\begin{tabular}{l*{5}{c}} \hline\hline\\ \multicolumn{5}{l}{\textit{Panel A: Characteristics of the owner}}\\\\") ///
	replace 

//middle panel 
esttab pnl2* using "tables/predictions_wtp_heterog.tex", ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mtitles(`mtitles2')  ///
	stats(N r2, label("Observations" "R$^2$")) ///
	se label wrap fragment ///
	nobaselevels nocons ///
	prehead("\hline \\ \multicolumn{5}{l}{\textit{Panel B: Leader beliefs and leader-owner relationships}} \\\\") ///
	append

//bottom panel 
esttab pnl3* using "tables/predictions_wtp_heterog.tex", ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mtitles(`mtitles3')  ///
	stats(N r2, label("Observations" "R$^2$")) ///
	se label wrap fragment ///
	nobaselevels nocons ///
	prefoot("\hline") ///
	prehead("\hline \\ \multicolumn{5}{l}{\textit{Panel C: Leader Characteristics}} \\\\") ///
	postfoot("\hline\hline \end{tabular}\par\medskip}{\footnotesize {\it Note: }`note'}") ///
	substitute(\_ _) ///
	append
estimates clear
drop x



*------------------------------------------------------------------------------
clear
*END-------
